package com.wiloon.java8x.thread.callable;

import java.util.concurrent.*;

/*
 * Created by roy on 6/27/17;
 */
public class CallableTest {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newCachedThreadPool();
        Task task = new Task();
        Future<Integer> result = executor.submit(task);
        executor.shutdown();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e1) {
            e1.printStackTrace();
        }


        System.out.println("主线程在执行任务.");
        System.out.println("future is done:" + result.isDone());
        try {
            System.out.println("task运行结果" + result.get());
            System.out.println("future is done:" + result.isDone());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        System.out.println("所有任务执行完毕");
    }
}


